<template>
	<view class="all-main">
		<view class="main">
			<!-- 结算模式 -->
			<view v-if="merchant.busType != 4" class="types">
				<view class="lefts">
					<text>结算模式</text>
				</view>
				<view class="rights" @click="accountTypeShow = true">
					<text>{{merchant.accountTypeText}}</text>
					<u-icon name="arrow-right" size="15"></u-icon>
				</view>
			</view>
			<!-- 经营者信息 -->
			<view v-if="merchant.busType == 4" class="legal-person">
				<view class="titles">
					<text>经营者信息</text>
					<u-icon name="question-circle" color="#f2873a" size="20" @click="custNameShow = true"></u-icon>
				</view>
				<view class="form-items">
					<view class="lefts">
						<text>证书类型</text>
					</view>
					<view class="rights">
						<text>{{merchant.nolegalCertTypeText}}</text>
					</view>
				</view>
				<view class="certificate">
					<view class="certificate-lefts">
						<view class="certificate-images" @click="imageClick(1)">
							<image id="img1" :src="image1" mode=""></image>
						</view>
						<view class="certificate-title">
							<text>经营者证件正面</text>
						</view>
					</view>
					<view class="certificate-rights">
						<view class="certificate-images" @click="imageClick(2)">
							<image id="img2" :src="image2" mode=""></image>
						</view>
						<view class="certificate-title">
							<text>经营者证件反面</text>
						</view>
					</view>
				</view>
				<view class="form-items">
					<view class="lefts">
						<text>经营者姓名</text>
					</view>
					<view class="rights">
						<input type="text" v-model="merchant.custName" placeholder="请与证件一致" />
					</view>
				</view>
				<view class="form-items">
					<view class="lefts">
						<text>经营者证件号</text>
					</view>
					<view class="rights">
						<input type="text" v-model="merchant.credNo" placeholder="请与证件一致" />
					</view>
				</view>
				<view class="form-items">
					<view class="lefts">
						<text>证件有效期</text>
					</view>
					<view class="rights" @click="credValidity(1)">
						<text>{{merchant.credText}}</text>
						<u-icon name="arrow-right" size="15"></u-icon>
					</view>
				</view>
			</view>
			<!-- 法人信息 -->
			<view v-else class="legal-person">
				<view class="titles">
					<text>法人信息</text>
				</view>
				<view class="form-items">
					<view class="lefts">
						<text>证书类型</text>
					</view>
					<view class="rights" @click="certificateTypeClick(1)">
						<text>{{merchant.nolegalCertTypeText}}</text>
						<u-icon name="arrow-right" size="15"></u-icon>
					</view>
				</view>
				<view class="certificate">
					<view class="certificate-lefts">
						<view class="certificate-images" @click="imageClick(3)">
							<image id="img3" :src="image3" mode=""></image>
						</view>
						<view class="certificate-title">
							<text>法人证件正面</text>
						</view>
					</view>
					<view class="certificate-rights">
						<view class="certificate-images" @click="imageClick(4)">
							<image id="img4" :src="image4" mode=""></image>
						</view>
						<view class="certificate-title">
							<text>法人证件反面</text>
						</view>
					</view>
				</view>
				<view class="form-items">
					<view class="lefts">
						<text>法人姓名</text>
					</view>
					<view class="rights">
						<input type="text" v-model="merchant.custName" placeholder="请与证件一致" />
					</view>
				</view>
				<view class="form-items">
					<view class="lefts">
						<text>法人证件号码</text>
					</view>
					<view class="rights">
						<input type="text" v-model="merchant.credNo" placeholder="请与证件一致" />
					</view>
				</view>
				<view class="form-items">
					<view class="lefts">
						<text>证件有效期</text>
					</view>
					<view class="rights" @click="credValidity(2)">
						<text>{{merchant.credText}}</text>
						<u-icon name="arrow-right" size="15"></u-icon>
					</view>
				</view>
				<view class="form-items">
					<view class="lefts">
						<text>法人居住地址</text>
					</view>
					<view class="rights">
						<input type="text" v-model="merchant.credAddress" placeholder="请输入法人居住地址" />
					</view>
				</view>
			</view>
			<!-- 经营者结算 -->
			<view v-if="merchant.busType == 4" class="legal-person">
				<view class="titles">
					<text>结算信息</text>
				</view>
				<view class="certificate">
					<view class="certificate-lefts">
						<view class="certificate-images" @click="imageClick(5)">
							<image id="img5" :src="image5" mode=""></image>
						</view>
						<view class="certificate-title">
							<text>结算银行卡正面</text>
						</view>
					</view>
					<view class="certificate-rights">
						<view class="certificate-images" @click="imageClick(6)">
							<image id="img6" :src="image6" mode=""></image>
						</view>
						<view class="certificate-title">
							<text>结算人站收银台</text>
						</view>
					</view>
				</view>
				<view class="form-items">
					<view class="lefts">
						<text>结算人姓名</text>
					</view>
					<view class="rights">
						<input type="text" v-model="merchant.accountName" placeholder="结算人姓名" />
					</view>
				</view>
				<view class="form-items">
					<view class="lefts">
						<text>结算银行卡</text>
					</view>
					<view class="rights">
						<input type="text" v-model="merchant.accountNo" placeholder="结算银行卡号" />
					</view>
				</view>
				<view class="form-items">
					<view class="lefts">
						<text>开户银行</text>
					</view>
					<view class="rights" @click="bankClick(1)">
						<text>{{merchant.bankName}}</text>
						<u-icon name="arrow-right" size="15"></u-icon>
					</view>
				</view>
			</view>
			<!-- 同法人结算 -->
			<view v-if="merchant.busType != 4 && merchant.accountType == '02'" class="legal-person">
				<view class="titles">
					<text>结算信息</text>
				</view>
				<view class="certificate-one">
					<view class="certificate-images" @click="imageClick(7)">
						<image id="img7" :src="image7" mode=""></image>
					</view>
					<view class="certificate-title">
						<text>结算银行卡正面</text>
					</view>
				</view>
				<view class="form-items">
					<view class="lefts">
						<text>结算户名</text>
					</view>
					<view class="rights">
						<input type="text" v-model="merchant.accountName" placeholder="法人姓名" />
					</view>
				</view>
				<view class="form-items">
					<view class="lefts">
						<text>结算银行卡</text>
					</view>
					<view class="rights">
						<input type="text" v-model="merchant.accountNo" placeholder="结算银行卡号" @blur="queryInfoByCard" />
					</view>
				</view>
				<view class="form-items">
					<view class="lefts">
						<text>开户银行</text>
					</view>
					<view class="rights" @click="bankClick(1)">
						<text>{{merchant.bankName}}</text>
						<u-icon name="arrow-right" size="15"></u-icon>
					</view>
				</view>
			</view>
			<!-- 非法人结算 -->
			<view v-if="merchant.busType != 4 && merchant.accountType == '03'" class="legal-person">
				<view class="titles">
					<text>结算信息</text>
				</view>
				<view class="form-items">
					<view class="lefts">
						<text>证件类型</text>
					</view>
					<view class="rights" @click="certificateTypeClick(2)">
						<text>{{merchant.accCredTypeText}}</text>
						<u-icon name="arrow-right" size="15"></u-icon>
					</view>
				</view>
				<view class="certificate">
					<view class="certificate-lefts">
						<view class="certificate-images" @click="imageClick(8)">
							<image id="img8" :src="image8" mode=""></image>
						</view>
						<view class="certificate-title">
							<text>结算人证件正面照</text>
						</view>
					</view>
					<view class="certificate-rights">
						<view class="certificate-images" @click="imageClick(9)">
							<image id="img9" :src="image9" mode=""></image>
						</view>
						<view class="certificate-title">
							<text>结算人证件反面照</text>
						</view>
					</view>
				</view>
				<view class="form-items">
					<view class="lefts">
						<text>结算人姓名</text>
					</view>
					<view class="rights">
						<input type="text" v-model="merchant.stlName" placeholder="结算人姓名" />
					</view>
				</view>
				<view class="form-items">
					<view class="lefts">
						<text>结算人证件号码</text>
					</view>
					<view class="rights">
						<input type="text" v-model="merchant.accCredNo" placeholder="结算人证件号码" />
					</view>
				</view>
				<view class="form-items">
					<view class="lefts">
						<text>证件有效期</text>
					</view>
					<view class="rights" @click="credValidity(3)">
						<text>{{merchant.accCredText}}</text>
						<u-icon name="arrow-right" size="15"></u-icon>
					</view>
				</view>
				<view class="certificate">
					<view class="certificate-lefts">
						<view class="certificate-images" @click="imageClick(10)">
							<image id="img10" :src="image10" mode=""></image>
						</view>
						<view class="certificate-title">
							<text>结算卡正面照</text>
						</view>
					</view>
					<view class="certificate-rights">
						<view class="certificate-images" @click="imageClick(11)">
							<image id="img11" :src="image11" mode=""></image>
						</view>
						<view class="certificate-title">
							<text>授权书</text>
							<text class="looks" @click="lookTmp(1)">(查看模板)</text>
						</view>
					</view>
				</view>
				<view class="certificate">
					<view class="certificate-lefts">
						<view class="certificate-images" @click="imageClick(12)">
							<image id="img12" :src="image12" mode=""></image>
						</view>
						<view class="certificate-title">
							<text>授权证明</text>
							<text class="looks" @click="lookTmp(2)">(查看模板)</text>
						</view>
					</view>
				</view>
				<view class="form-items">
					<view class="lefts">
						<text>结算银行卡</text>
					</view>
					<view class="rights">
						<input type="text" v-model="merchant.accountNo" placeholder="结算银行卡号" />
					</view>
				</view>
				<view class="form-items">
					<view class="lefts">
						<text>开户银行</text>
					</view>
					<view class="rights" @click="bankClick(1)">
						<text>{{merchant.bankName}}</text>
						<u-icon name="arrow-right" size="15"></u-icon>
					</view>
				</view>
			</view>
			<!-- 对公结算 -->
			<view v-if="merchant.busType != 4 && merchant.accountType == '01'" class="legal-person">
				<view class="titles">
					<text>结算信息</text>
				</view>
				<view class="certificate-one">
					<view class="certificate-images" @click="imageClick(13)">
						<image id="img13" :src="image13" mode=""></image>
					</view>
					<view class="certificate-title">
						<text>开户许可证照/印鉴卡</text>
					</view>
				</view>
				<view class="form-items">
					<view class="lefts">
						<text>结算户名</text>
					</view>
					<view class="rights">
						<input type="text" v-model="merchant.accountName" placeholder="结算户名" />
					</view>
				</view>
				<view class="form-items">
					<view class="lefts">
						<text>结算账户</text>
					</view>
					<view class="rights">
						<input type="text" v-model="merchant.accountNo" placeholder="结算账户" />
					</view>
				</view>
				<view class="form-items">
					<view class="lefts">
						<text>开户银行</text>
					</view>
					<view class="rights" @click="bankClick(1)">
						<text>{{merchant.bankName}}</text>
						<u-icon name="arrow-right" size="15"></u-icon>
					</view>
				</view>
				<view class="form-items">
					<view class="lefts">
						<text>开户省市</text>
					</view>
					<view class="rights" @click="addressClick">
						<text>{{merchant.bankAddress}}</text>
						<u-icon name="arrow-right" size="15"></u-icon>
					</view>
				</view>
				<view class="form-items">
					<view class="lefts">
						<text>开户支行</text>
					</view>
					<view class="rights" @click="bankClick(2)">
						<text>{{merchant.branchname}}</text>
						<u-icon name="arrow-right" size="15"></u-icon>
					</view>
				</view>
			</view>
			<view class="occupy_position"></view>
			<view v-if="merchant.custId == '' || merchant.custId == null" class="bottom-btn">
				<view class="btn-left" @click="saveData(2)">
					<text>暂存</text>
				</view>
				<view class="btn-right" @click="saveData(1)">
					<text>下一步</text>
				</view>
			</view>
			<view v-else class="bottom-btn">
				<view class="btns" @click="saveData(1)">
					<text>下一步</text>
				</view>
			</view>
			<!-- 插件 -->
			<u-picker :show="accountTypeShow" :columns="accountTypeList" keyName="label" :closeOnClickOverlay="true"
				@confirm="accountTypeConfirm" @close="accountTypeShow = false"
				@cancel="accountTypeShow = false"></u-picker>
			<u-picker :show="certificateTypeShow" :columns="certificateTypeList" keyName="label"
				:closeOnClickOverlay="true" @confirm="certificateTypeConfirm" @close="certificateTypeShow = false"
				@cancel="certificateTypeShow = false"></u-picker>
			<u-datetime-picker :show="certificate_validity_showA" title="开始时间" :minDate="-788950800000"
				v-model="startDate" :maxDate="4260182400000" mode="date" :closeOnClickOverlay="true"
				@confirm='startDateConfirm' @close="certificate_validity_showA = false"
				@cancel="certificate_validity_showA = false"></u-datetime-picker>
			<u-datetime-picker :show="certificate_validity_showB" title="截止时间" :minDate="-788950800000"
				v-model="endDate" :maxDate="4260182400000" mode="date" :closeOnClickOverlay="true"
				@confirm='endDateConfirm' @close="certificate_validity_showB = false"
				@cancel="certificate_validity_showB = false"></u-datetime-picker>
			<u-modal :show="custNameShow" :title="custNameTitle" :content='custNameContent'
				@confirm="custNameShow = false"></u-modal>
			<u-popup :show="image_show" @close="image_show = false">
				<view class="images_box">
					<view class="image_box">
						<text class="" @click="_picture">拍照</text>
						<text class="" @click="_getFile">手机相册选择</text>
					</view>
					<text @click.stop="image_show = false">取消</text>
				</view>
			</u-popup>
			<u-picker :show="addressShow" :columns="provinceData" keyName="label" :closeOnClickOverlay="true"
				@confirm="confirmAddress" @close="addressShow = false" @cancel="addressShow = false"></u-picker>
			<u-picker :show="addressShowB" :columns="cityData" keyName="label" :closeOnClickOverlay="true"
				@confirm="confirmAddressB" @close="addressShowB = false" @cancel="addressShowB = false"></u-picker>
		</view>
	</view>
</template>

<script>
	var util = require('@/util/request.js');
	import {
		pathToBase64,
		base64ToPath
	} from '@/js_sdk/mmmm-image-tools/index.js'
	export default {
		data() {
			return {
				image1: '/static/idcard_b.png',
				image2: '/static/idcard_a.png',
				image3: '/static/idcard_b.png',
				image4: '/static/idcard_a.png',
				image5: '/static/bank.png',
				image6: '/static/business_license.png',
				image7: '/static/bank.png',
				image8: '/static/idcard_b.png',
				image9: '/static/idcard_a.png',
				image10: '/static/bank.png',
				image11: '/static/business_license.png',
				image12: '/static/business_license.png',
				image13: '/static/business_license.png',
				accountTypeList: [],
				accountTypeShow: false,
				certificateType: 1,
				certificateTypeList: [],
				certificateTypeShow: false,
				credValidityType: 1,
				certificate_validity_showA: false,
				certificate_validity_showB: false,
				startDate: '',
				endDate: '',
				custNameShow: false,
				custNameTitle: '',
				custNameContent: '',
				image_show: false,
				flag: '',
				addressShow: false,
				addressShowB: false,
				provinceData: [],
				cityData: [],
				provCode: '',
				cityCode: '',
				address: '',
				merchant: {
					id: '',
					accountType: '', // 结算模式
					accountTypeText: '请选择', // 结算模式名称
					custName: '', // 经营者姓名
					nolegalCertType: '', // 法人证件类型
					nolegalCertTypeText: '请选择', // 法人证件类型名称
					credNo: '', // 法人证件号
					credStartDate: '', // 法人身份证有效期开始日期
					credEndDate: '', // 法人身份证有效期结束日期
					credText: '请选择', // 法人身份证有效期
					credAddress: '', // 法人地址
					accountName: '', // 结算户名
					accountNo: '', // 结算账号
					bankCode: '', // 开户行（银行缩写）
					bankName: '请选择', // 开户行名称
					provCode: '', // 省 - 联行号
					cityCode: '', // 市 - 联行号
					bankAddress: '请选择', // 开户行省市
					branchname: '', // 支行名称
					bankno: '', // 支行联行号
					stlName: '', // 非法人结算人姓名
					accCredType: '', // 非法人-证件类型
					accCredTypeText: '请选择', // 非法人-证件类型名称
					accCredNo: '', // 非法人结算人证件号
					accCredStartDate: '', // 非法人结算人证件有效期开始
					accCredEndDate: '', // 非法人结算人证件有效期结束
					accCredText: '请选择', // 非法人结算人证件有效期
				}
			};
		},
		onLoad(e) {
			this.merchant.id = e.id
			this.getAccountType()
			this.startDate = Number(new Date())
			this.endDate = Number(new Date())
		},
		mounted() {
			var that = this
			uni.$on('bankCode', function(data) {
				that.merchant.bankCode = data
			})
			uni.$on('bankName', function(data) {
				that.merchant.bankName = data
			})
			uni.$on('bankNo', function(data) {
				that.merchant.bankno = data
			})
			uni.$on('branchName', function(data) {
				that.merchant.branchname = data
			})
			uni.$on('data_id', function(data) {
				that.getMerchantEntry(data)
			})
		},
		methods: {
			// 获取商户进件信息
			async getMerchantEntry() {
				uni.showLoading({
					title: '加载中'
				});
				const {
					data: res
				} = await this.$myHttp({
					url: 'v1/getMerchantEntry',
					data: {
						id: this.merchant.id
					}
				});
				uni.hideLoading()
				if (res.code == 200) {
					this.merchant = res.data
					if (this.merchant.accountType == null || this.merchant.accountType == '') {
						this.merchant.accountType = '02'
						this.merchant.accountTypeText = '同法人结算'
					}
					this.merchant.pageSize = 2
					if (this.merchant.busType == 4) {
						this.merchant.nolegalCertType = 0
						this.merchant.nolegalCertTypeText = "身份证"
						this.getCustNameMsg()
					}
					if (this.merchant.images == null) {
						this.merchant.images = {
							credPhotoFront: '', // 身份证正面照
							credPhotoBack: '', // 身份证反面照
							authPic: '', // 结算卡正面照
							credPicF: '', // 非法人对私身份证正面照
							credPicB: '', // 非法人对私身份证反面照
							stlAuth: '', // 非法人授权结算书合影
							authCert: '', // 非法人对私上传的授权书
							stlDoor: '', // 结算人站门头照
							jsrcPhoto: '', // 结算人站收银台照
							indoorScenesPhoto: '', // 经营场所内景照
							doorHeaderPhoto: '', // 经营场所门头照
							cashierPhoto: '', // 收银台照
						}
					}
					if (this.merchant.credText == null) {
						this.merchant.credText = '请选择'
					}
					if (this.merchant.bankName == null) {
						this.merchant.bankName = '请选择'
					}
					if (this.merchant.accCredText == null) {
						this.merchant.accCredText = '请选择'
					}
					if (this.merchant.nolegalCertTypeText == null) {
						this.merchant.nolegalCertTypeText = '请选择'
					}
					if (this.merchant.accCredTypeText == null) {
						this.merchant.accCredTypeText = '请选择'
					}
					if (this.merchant.branchname == null) {
						this.merchant.branchname = '请选择'
					}
					if (this.merchant.bankAddress == null) {
						this.merchant.bankAddress = '请选择'
					}

					if (this.merchant.images != null) {
						if (this.merchant.images.credPhotoFront != null && this.merchant.images.credPhotoFront != '') {
							if (this.merchant.busType == 4) {
								this.image1 = util.API_URL + this.merchant.images.credPhotoFront
							} else {
								this.image3 = util.API_URL + this.merchant.images.credPhotoFront
							}
						}
						if (this.merchant.images.credPhotoBack != null && this.merchant.images.credPhotoBack != '') {
							if (this.merchant.busType == 4) {
								this.image2 = util.API_URL + this.merchant.images.credPhotoBack
							} else {
								this.image4 = util.API_URL + this.merchant.images.credPhotoBack
							}
						}
						if (this.merchant.images.authPic != null && this.merchant.images.authPic != '') {
							if (this.merchant.busType == 4) {
								this.image5 = util.API_URL + this.merchant.images.authPic
							} else {
								if (this.merchant.accountType == '01') {
									this.image13 = util.API_URL + this.merchant.images.authPic
								} else if (this.merchant.accountType == '02') {
									this.image7 = util.API_URL + this.merchant.images.authPic
								} else if (this.merchant.accountType == '03') {
									this.image10 = util.API_URL + this.merchant.images.authPic
								}
							}
						}
						if (this.merchant.images.stlDoor != null && this.merchant.images.stlDoor != '') {
							this.image6 = util.API_URL + this.merchant.images.stlDoor
						}
						if (this.merchant.images.credPicF != null && this.merchant.images.credPicF != '') {
							this.image8 = util.API_URL + this.merchant.images.credPicF
						}
						if (this.merchant.images.credPicB != null && this.merchant.images.credPicB != '') {
							this.image9 = util.API_URL + this.merchant.images.credPicB
						}
						if (this.merchant.images.authCert != null && this.merchant.images.authCert != '') {
							this.image11 = util.API_URL + this.merchant.images.authCert
						}
						if (this.merchant.images.stlAuth != null && this.merchant.images.stlAuth != '') {
							this.image12 = util.API_URL + this.merchant.images.stlAuth
						}
					}
				}
			},
			// 获取结算模式
			async getAccountType() {
				uni.showLoading({
					title: '加载中'
				});
				const {
					data: res
				} = await this.$myHttp({
					url: 'v1/getSettlementType',
				});
				uni.hideLoading()
				if (res.code == 200) {
					this.accountTypeList = [res.data]
					this.merchant.accountType = res.data[0].id
					this.merchant.accountTypeText = res.data[0].label
					this.getMerchantEntry()
				}
			},
			// 获取经营者信息 - 描述
			async getCustNameMsg() {
				uni.showLoading({
					title: '加载中'
				});
				const {
					data: res
				} = await this.$myHttp({
					url: 'v1/getCustNameMsg',
				});
				uni.hideLoading()
				if (res.code == 200) {
					this.custNameTitle = res.data.title
					this.custNameContent = res.data.content
				}
			},
			// 获取证书类型
			async getCertificateType() {
				uni.showLoading({
					title: '加载中'
				});
				const {
					data: res
				} = await this.$myHttp({
					url: 'v1/getCertificateType',
				});
				uni.hideLoading()
				if (res.code == 200) {
					this.certificateTypeList = [res.data]
					this.certificateTypeShow = true
				}
			},
			// 选择结算模式
			accountTypeConfirm(e) {
				this.merchant.accountType = e.value[0].id
				this.merchant.accountTypeText = e.value[0].label
				this.accountTypeShow = false
			},
			// 点击证书
			certificateTypeClick(type) {
				this.certificateType = type
				if (this.certificateTypeList.length <= 0) {
					this.getCertificateType()
				} else {
					this.certificateTypeShow = true
				}
			},
			// 选择证书
			certificateTypeConfirm(e) {
				if (this.certificateType == 1) {
					this.merchant.nolegalCertType = e.value[0].id
					this.merchant.nolegalCertTypeText = e.value[0].label
				} else {
					this.merchant.accCredType = e.value[0].id
					this.merchant.accCredTypeText = e.value[0].label
				}
				this.certificateTypeShow = false
			},
			// 证件有效期点击
			credValidity(type) {
				this.credValidityType = type
				this.startDate = Number(new Date())
				this.endDate = Number(new Date())
				this.certificate_validity_showA = true
			},
			// 证书有效时间 - 开始时间选择
			startDateConfirm(e) {
				if (this.credValidityType == 1) {
					this.merchant.credStartDate = e.value
				} else if (this.credValidityType == 2) {
					this.merchant.credStartDate = e.value
				} else if (this.credValidityType == 3) {
					this.merchant.accCredStartDate = e.value
				}
				this.certificate_validity_showA = false
				this.certificate_validity_showB = true
			},
			// 证书有效时间 - 截止时间选择
			endDateConfirm(e) {
				const timeFormat = uni.$u.timeFormat
				if (this.credValidityType == 1) {
					this.merchant.credEndDate = e.value
					this.merchant.credText = timeFormat(this.merchant.credStartDate, 'yyyy-mm-dd') +
						' 至 ' + timeFormat(e.value, 'yyyy-mm-dd')
				} else if (this.credValidityType == 2) {
					this.merchant.credEndDate = e.value
					this.merchant.credText = timeFormat(this.merchant.credStartDate, 'yyyy-mm-dd') +
						' 至 ' + timeFormat(e.value, 'yyyy-mm-dd')
				} else if (this.credValidityType == 3) {
					this.merchant.accCredEndDate = e.value
					this.merchant.accCredText = timeFormat(this.merchant.accCredStartDate, 'yyyy-mm-dd') +
						' 至 ' + timeFormat(e.value, 'yyyy-mm-dd')
				}
				this.certificate_validity_showB = false
			},
			// 查看模版
			lookTmp(type) {
				if (type == 1) {
					uni.navigateTo({
						url: '/pages/index/guotong/filetemplate?type=2'
					})
				} else {
					uni.navigateTo({
						url: '/pages/index/guotong/filetemplate?type=3'
					})
				}
			},
			// 文件上传 - 点击
			imageClick(type) {
				if (type == 3 || type == 4) {
					if (this.merchant.nolegalCertTypeText == '请选择') {
						uni.showToast({
							title: '请先选择法人证书类型',
							icon: 'none',
							duration: 3000
						})
						return false
					}
				}
				if (type == 8 || type == 9) {
					if (this.merchant.nolegalCertTypeText == '请选择') {
						uni.showToast({
							title: '请先选择结算信息证书类型',
							icon: 'none',
							duration: 3000
						})
						return false
					}
				}
				if (type == 1 || type == 3) {
					this.flag = 1
				}
				if (type == 2 || type == 4) {
					this.flag = 2
				}
				if (type == 5 || type == 7 || type == 10 || type == 13) {
					this.flag = 3
				}
				if (type == 6) {
					this.flag = 16
				}
				if (type == 8) {
					this.flag = 13
				}
				if (type == 9) {
					this.flag = 14
				}
				if (type == 11) {
					this.flag = 15
				}
				if (type == 12) {
					this.flag = 17
				}
				this.image_types = type
				this.image_show = true
			},
			// 拍照
			_getFile() {
				let _this = this
				uni.chooseImage({
					count: 1, //默认9
					sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
					sourceType: ['album'], //从相册选择
					success: function(res) {
						pathToBase64(res.tempFilePaths[0])
							.then(base64 => {
								_this.uploadFile(base64)
								_this.image_show = false
							})
							.catch(error => {})
					}
				});
			},
			// 手机相册
			_picture() {
				let _this = this
				uni.chooseImage({
					count: 1, //默认9
					sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
					sourceType: ['camera'], //从相机选择
					success: function(res) {
						pathToBase64(res.tempFilePaths[0])
							.then(base64 => {
								_this.uploadFile(base64)
								_this.image_show = false
							})
							.catch(error => {})
					}
				});
			},
			// 上传图片
			async uploadFile(base) {
				uni.showLoading({
					title: '上传中'
				});
				const {
					data: res
				} = await this.$myHttp({
					url: 'common/gtUploadFile',
					data: {
						file: base,
						type: this.image_types,
						flag: this.flag,
						timestamp: this.merchant.timestamp,
						custLogin: this.merchant.custLogin,
						custId: this.merchant.custId
					}
				});
				uni.hideLoading()
				if (res.code == 200) {
					this.merchant.timestamp = res.data.timestamp
					if (this.image_types == 1) {
						this.image1 = base
						this.merchant.images.credPhotoFront = res.data.url
					} else if (this.image_types == 2) {
						this.image2 = base
						this.merchant.images.credPhotoBack = res.data.url
					} else if (this.image_types == 3) {
						this.image3 = base
						this.merchant.images.credPhotoFront = res.data.url
					} else if (this.image_types == 4) {
						this.image4 = base
						this.merchant.images.credPhotoBack = res.data.url
					} else if (this.image_types == 5) {
						this.image5 = base
						this.merchant.images.authPic = res.data.url
					} else if (this.image_types == 6) {
						this.image6 = base
						this.merchant.images.stlDoor = res.data.url
					} else if (this.image_types == 7) {
						this.image7 = base
						this.merchant.images.authPic = res.data.url
					} else if (this.image_types == 8) {
						this.image8 = base
						this.merchant.images.credPicF = res.data.url
					} else if (this.image_types == 9) {
						this.image9 = base
						this.merchant.images.credPicB = res.data.url
					} else if (this.image_types == 10) {
						this.image10 = base
						this.merchant.images.authPic = res.data.url
					} else if (this.image_types == 11) {
						this.image11 = base
						this.merchant.images.authCert = res.data.url
					} else if (this.image_types == 12) {
						this.image12 = base
						this.merchant.images.stlAuth = res.data.url
					} else if (this.image_types == 13) {
						this.image13 = base
						this.merchant.images.authPic = res.data.url
					}
				} else {
					uni.showToast({
						title: res.msg,
						icon: 'none',
						duration: 3000
					})
				}
			},
			// 根据银行卡号获取银行信息
			async queryInfoByCard() {
				uni.showLoading({
					title: '加载中'
				});
				const {
					data: res
				} = await this.$myHttp({
					url: 'v1/queryInfoByCard',
					data: {
						cardNo: this.merchant.accountNo
					}
				});
				uni.hideLoading()
				if (res.code == 200) {
					this.merchant.bankCode = res.data.bankCode
					this.merchant.bankName = res.data.bankName
				}
			},
			// 点击开户行
			bankClick(type) {
				if (type == 1) {
					uni.navigateTo({
						url: '/pages/index/guotong/bank?type=' + type
					})
				} else {
					if (this.merchant.bankCode == '' || this.merchant.bankCode == null) {
						uni.showToast({
							title: '请选择开户银行',
							icon: 'none',
							duration: 3000
						})
						return false
					}
					if (this.merchant.cityCode == '' || this.merchant.cityCode == null) {
						uni.showToast({
							title: '请选择开户省市',
							icon: 'none',
							duration: 3000
						})
						return false
					}
					uni.navigateTo({
						url: '/pages/index/guotong/bank?type=' + type + '&bankCode=' + this.merchant.bankCode +
							'&code=' + this.merchant.cityCode
					})
				}
			},
			// 点击开户省市
			addressClick() {
				if (this.provinceData.length <= 0) {
					this.getPublicProvince()
				} else {
					this.addressShow = true
				}
			},
			// 选择地址
			confirmAddress(val) {
				this.merchant.provCode = val.value[0].id
				this.merchant.bankAddress = val.value[0].label
				this.addressShow = false
				this.getPublicCity()
			},
			// 选择地址
			confirmAddressB(val) {
				this.merchant.cityCode = val.value[0].id
				this.merchant.bankAddress += val.value[0].label
				this.addressShowB = false
			},
			// 获取银行省信息-联行号
			async getPublicProvince() {
				uni.showLoading({
					title: '加载中'
				});
				const {
					data: res
				} = await this.$myHttp({
					url: 'v1/getPublicProvince',
				});
				uni.hideLoading()
				if (res.code == 200) {
					this.provinceData = [res.data]
					this.addressShow = true
				}
			},
			// 获取银行市信息-联行号
			async getPublicCity() {
				uni.showLoading({
					title: '加载中'
				});
				const {
					data: res
				} = await this.$myHttp({
					url: 'v1/getPublicCity',
					data: {
						code: this.merchant.provCode
					}
				});
				uni.hideLoading()
				if (res.code == 200) {
					this.cityData = [res.data]
					this.addressShowB = true
				}
			},
			// 保存数据
			saveData(type) {
				var _this = this
				var msg = ''
				this.merchant.saveType = type
				if (this.merchant.busType == 4) {
					if (this.merchant.images.credPhotoFront == '' || this.merchant.images.credPhotoFront == null) {
						uni.showToast({
							title: '请上传经营者证件正面',
							icon: 'none',
							duration: 3000
						})
						return false
					}
					if (this.merchant.images.credPhotoBack == '' || this.merchant.images.credPhotoBack == null) {
						uni.showToast({
							title: '请上传经营者证件反面',
							icon: 'none',
							duration: 3000
						})
						return false
					}
					if (this.merchant.custName == '' || this.merchant.custName == null) {
						uni.showToast({
							title: '请输入经营者姓名',
							icon: 'none',
							duration: 3000
						})
						return false
					}
					if (this.merchant.credNo == '' || this.merchant.credNo == null) {
						uni.showToast({
							title: '请输入经营者证件号',
							icon: 'none',
							duration: 3000
						})
						return false
					}
					if (this.merchant.credText == '请选择') {
						uni.showToast({
							title: '请选择证件有效期',
							icon: 'none',
							duration: 3000
						})
						return false
					}
					if (this.merchant.images.authPic == '' || this.merchant.images.authPic == null) {
						uni.showToast({
							title: '请上传结算银行卡正面',
							icon: 'none',
							duration: 3000
						})
						return false
					}
					if (this.merchant.images.stlDoor == '' || this.merchant.images.stlDoor == null) {
						uni.showToast({
							title: '请上传结算人站收银台',
							icon: 'none',
							duration: 3000
						})
						return false
					}
					if (this.merchant.accountName == '' || this.merchant.accountName == null) {
						uni.showToast({
							title: '请输入结算人姓名',
							icon: 'none',
							duration: 3000
						})
						return false
					}
					if (this.merchant.accountNo == '' || this.merchant.accountNo == null) {
						uni.showToast({
							title: '请输入结算银行卡',
							icon: 'none',
							duration: 3000
						})
						return false
					}
					if (this.merchant.bankName == '请选择') {
						uni.showToast({
							title: '请选择开户银行',
							icon: 'none',
							duration: 3000
						})
						return false
					}
				} else {
					if (this.merchant.images.credPhotoFront == '' || this.merchant.images.credPhotoFront == null) {
						uni.showToast({
							title: '请上传法人证件正面',
							icon: 'none',
							duration: 3000
						})
						return false
					}
					if (this.merchant.images.credPhotoBack == '' || this.merchant.images.credPhotoBack == null) {
						uni.showToast({
							title: '请上传法人证件反面',
							icon: 'none',
							duration: 3000
						})
						return false
					}
					if (this.merchant.custName == '' || this.merchant.custName == null) {
						uni.showToast({
							title: '请输入法人姓名',
							icon: 'none',
							duration: 3000
						})
						return false
					}
					if (this.merchant.credNo == '' || this.merchant.credNo == null) {
						uni.showToast({
							title: '请输入法人证件号码',
							icon: 'none',
							duration: 3000
						})
						return false
					}
					if (this.merchant.credText == '请选择') {
						uni.showToast({
							title: '请选择证件有效期',
							icon: 'none',
							duration: 3000
						})
						return false
					}
					if (this.merchant.credAddress == '' || this.merchant.credAddress == null) {
						uni.showToast({
							title: '请输入法人居住地址',
							icon: 'none',
							duration: 3000
						})
						return false
					}
					if (this.merchant.accountType == '01') {
						if (this.merchant.images.authPic == '' || this.merchant.images.authPic == null) {
							uni.showToast({
								title: '请上传开户许可证照/印鉴卡',
								icon: 'none',
								duration: 3000
							})
							return false
						}
						if (this.merchant.accountName == '' || this.merchant.accountName == null) {
							uni.showToast({
								title: '请输入结算户名',
								icon: 'none',
								duration: 3000
							})
							return false
						}
						if (this.merchant.accountNo == '' || this.merchant.accountNo == null) {
							uni.showToast({
								title: '请输入结算账户',
								icon: 'none',
								duration: 3000
							})
							return false
						}
						if (this.merchant.bankName == '请选择') {
							uni.showToast({
								title: '请选择开户银行',
								icon: 'none',
								duration: 3000
							})
							return false
						}
						if (this.merchant.bankAddress == '请选择') {
							uni.showToast({
								title: '请选择开户省市',
								icon: 'none',
								duration: 3000
							})
							return false
						}
						if (this.merchant.branchname == '' || this.merchant.branchname == null) {
							uni.showToast({
								title: '请选择开户支行',
								icon: 'none',
								duration: 3000
							})
							return false
						}
					} else if (this.merchant.accountType == '02') {
						if (this.merchant.images.authPic == '' || this.merchant.images.authPic == null) {
							uni.showToast({
								title: '请上传结算银行卡正面',
								icon: 'none',
								duration: 3000
							})
							return false
						}
						if (this.merchant.accountName == '' || this.merchant.accountName == null) {
							uni.showToast({
								title: '请输入法人姓名',
								icon: 'none',
								duration: 3000
							})
							return false
						}
						if (this.merchant.accountNo == '' || this.merchant.accountNo == null) {
							uni.showToast({
								title: '请输入结算银行卡',
								icon: 'none',
								duration: 3000
							})
							return false
						}
						if (this.merchant.bankName == '请选择') {
							uni.showToast({
								title: '请选择开户银行',
								icon: 'none',
								duration: 3000
							})
							return false
						}
					} else if (this.merchant.accountType == '03') {
						if (this.merchant.images.credPicF == '' || this.merchant.images.credPicF == null) {
							uni.showToast({
								title: '请上传结算人证件正面照',
								icon: 'none',
								duration: 3000
							})
							return false
						}
						if (this.merchant.images.credPicB == '' || this.merchant.images.credPicB == null) {
							uni.showToast({
								title: '请上传结算人证件反面照',
								icon: 'none',
								duration: 3000
							})
							return false
						}
						if (this.merchant.stlName == '' || this.merchant.stlName == null) {
							uni.showToast({
								title: '请输入结算人姓名',
								icon: 'none',
								duration: 3000
							})
							return false
						}
						if (this.merchant.accCredNo == '' || this.merchant.accCredNo == null) {
							uni.showToast({
								title: '请输入结算人证件号码',
								icon: 'none',
								duration: 3000
							})
							return false
						}
						if (this.merchant.accCredText == '请选择') {
							uni.showToast({
								title: '请选择证件有效期',
								icon: 'none',
								duration: 3000
							})
							return false
						}
						if (this.merchant.images.authPic == '' || this.merchant.images.authPic == null) {
							uni.showToast({
								title: '请上传结算卡正面照',
								icon: 'none',
								duration: 3000
							})
							return false
						}
						if (this.merchant.images.authCert == '' || this.merchant.images.authCert == null) {
							uni.showToast({
								title: '请上传授权书',
								icon: 'none',
								duration: 3000
							})
							return false
						}
						if (this.merchant.images.stlAuth == '' || this.merchant.images.stlAuth == null) {
							uni.showToast({
								title: '请上传授权证明',
								icon: 'none',
								duration: 3000
							})
							return false
						}
						if (this.merchant.accountNo == '' || this.merchant.accountNo == null) {
							uni.showToast({
								title: '请输入结算银行卡',
								icon: 'none',
								duration: 3000
							})
							return false
						}
						if (this.merchant.bankName == '请选择') {
							uni.showToast({
								title: '请选择开户银行',
								icon: 'none',
								duration: 3000
							})
							return false
						}
					}
				}
				if (type == 2) {
					msg = '是否要选择暂存当前信息？'
				} else {
					msg = '是否确认当前信息，进行下一步？'
				}
				uni.showModal({
					content: msg,
					success: (res) => {
						if (res.confirm) {
							_this.saveDataFun()
						}
					}
				})
			},
			// 提交数据
			async saveDataFun() {
				uni.showLoading({
					title: '加载中'
				});
				const {
					data: res
				} = await this.$myHttp({
					url: 'v1/merchantEntry',
					data: this.merchant,
				});
				uni.hideLoading()
				if (res.code == 200) {
					if (this.merchant.saveType == 2) {
						uni.reLaunch({
							url: '/pages/index/guotong/lists'
						});
					} else {
						uni.navigateTo({
							url: '/pages/index/guotong/other?id=' + this.merchant.id
						})
					}
				}
			},
		}
	}
</script>

<style lang="scss">
	.all-main {
		.main {
			padding: 30rpx;

			.types {
				display: flex;
				justify-content: space-between;
				background-color: #ffffff;
				padding: 30rpx;
				margin-bottom: 30rpx;

				.rights {
					display: flex;
					align-items: center;
					color: #909399;

					text {
						padding-right: 8rpx;
					}
				}
			}

			.legal-person {
				background-color: #ffffff;
				border-radius: 16rpx;
				margin-bottom: 30rpx;

				.titles {
					display: flex;
					align-items: center;
					padding: 30rpx;
					font-weight: bold;
					border-bottom: 1px solid #f4f4f5;

					text {
						padding-right: 16rpx;
					}
				}

				.form-items {
					display: flex;
					justify-content: space-between;
					padding: 30rpx;
					border-bottom: 1px solid #f4f4f5;

					.rights {
						display: flex;
						color: #909399;
						width: 60%;
						justify-content: flex-end;
						align-items: center;

						input {
							text-align: right;
							font-size: 28rpx;
						}

						.inputs {
							margin-right: 10rpx;
						}

						text {
							padding-right: 10rpx;
							color: #909399;
							font-size: 28rpx;
						}
					}
				}

				.certificate-one {
					padding: 20rpx 0;

					.certificate-images {
						text-align: center;
						position: relative;

						image {
							padding: 20rpx 30rpx;
							border: 2px solid #f4f4f5;
							border-radius: 16rpx;
							width: 95px;
							height: 60px;
						}
					}

					.certificate-title {
						color: #909399;
						text-align: center;
						font-size: 28rpx;

						.looks {
							color: #f2873a;
						}
					}
				}

				.certificate {
					display: flex;
					justify-content: space-between;

					.certificate-lefts {
						width: 50%;
						padding: 20rpx 0;
					}

					.certificate-rights {
						width: 50%;
						padding: 20rpx 0;
					}

					.certificate-images {
						text-align: center;
						position: relative;

						image {
							padding: 20rpx 30rpx;
							border: 2px solid #f4f4f5;
							border-radius: 16rpx;
							width: 95px;
							height: 60px;
						}
					}

					.certificate-title {
						color: #909399;
						text-align: center;
						font-size: 28rpx;

						.looks {
							color: #f2873a;
						}
					}
				}
			}

			.occupy_position {
				height: 110rpx;
			}

			.bottom-btn {
				position: fixed;
				left: 0;
				right: 0;
				bottom: 0;
				padding: 30rpx;
				background-color: #ffffff;
				display: flex;
				justify-content: space-between;

				.btn-left {
					width: 48%;
					height: 80rpx;
					display: flex;
					justify-content: center;
					align-items: center;
					background-color: #f8ece3;
					color: #f2873a;
					border-radius: 14rpx;
				}

				.btn-right {
					width: 48%;
					height: 80rpx;
					display: flex;
					justify-content: center;
					align-items: center;
					background-color: #f2873a;
					color: #ffffff;
					border-radius: 14rpx;
				}
				
				.btns {
					width: 100%;
					height: 80rpx;
					display: flex;
					justify-content: center;
					align-items: center;
					background-color: #f2873a;
					color: #ffffff;
					border-radius: 14rpx;
				}
			}

			.images_box {
				box-sizing: border-box;

				.phone {
					margin-bottom: 20rpx;
					border-bottom: #eee 1px solid;
					padding: 30rpx;
				}

				.image_box {
					margin-bottom: 30rpx;

					text {
						border-bottom: #eee solid 1px;
						padding: 20rpx 0;
						margin: 0;
					}
				}

				text {
					font-size: 32rpx;
					color: #1296db;
					text-align: center;
					display: block;
					margin-bottom: 30rpx;
					transition: all 0.5s;
				}

				text:active {
					background-color: #ebebeb;
				}
			}
		}
	}
</style>